package com.hys.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
	
	/** 消息交换机的名字*/
    public static final String FanoutExchange = "FanoutExchange";
    
    public static final String DirectExchange = "DirectExchange";
    
    public static final String TopicExchange = "TopicExchange";

    
    public static final String routingKey1 = "hello";
    
    public static final String routingKey2 = "hellos";
    
    public static final String DirectExchangeKey1 = "DirectExchangeKey1";
    
    public static final String DirectExchangeKey2 = "DirectExchangeKey2";
    
    public static final String TopicName= "TopicName.single";
    
    public static final String TopicNames = "TopicName.all";
    
    public static final String TopicNamesAll = "TopicName.*";






    
    
   /**
    * 广播
    * @return
    */
    @Bean  
    public FanoutExchange defaultExchange() { 
    	FanoutExchange exchange = new FanoutExchange(FanoutExchange,true,true);
    	return exchange;
    }
    /**
     * 直连型
     * @return
     */
    @Bean  
    public DirectExchange directExchange() { 
    	DirectExchange exchange = new DirectExchange(DirectExchange,true,true);
    	return exchange;
    }
    
    @Bean  
    public TopicExchange topicExchangeExchange(){
    	TopicExchange  exchange = new TopicExchange(TopicExchange);
    	return exchange;
    }
    
    
    @Bean  
    public Binding binding() {  
    	Binding binding = BindingBuilder.bind(helloQueue()).to(defaultExchange());
    	return binding;
    }
    
    @Bean  
    public Binding binding2() {  
    	Binding binding = BindingBuilder.bind(hellosQueue()).to(defaultExchange());
    	return binding;
    }
	
    @Bean  
    public Binding binding3() {  
    	Binding binding = BindingBuilder.bind(directExchangeKey1Queue()).to(directExchange()).with(DirectExchangeKey1);
    	return binding;
    }
    
    @Bean  
    public Binding binding4() {  
    	Binding binding = BindingBuilder.bind(directExchangeKey2Queue()).to(directExchange()).with(DirectExchangeKey2);
    	return binding;
    }
    
    @Bean  
    public Binding binding5() {  
    	Binding binding = BindingBuilder.bind(TopicNameQueue()).to(topicExchangeExchange()).with(TopicName);
    	return binding;
    }
    
    @Bean  
    public Binding binding6() {  
    	Binding binding = BindingBuilder.bind(TopicNameQueues()).to(topicExchangeExchange()).with(TopicNamesAll);
    	return binding;
    }
    
    @Bean
    public Queue helloQueue() {
        return new Queue(routingKey1,false);
    }
    
    @Bean
    public Queue hellosQueue() {
        return new Queue(routingKey2,false,false,false,null);
    }
    
    @Bean
    public Queue directExchangeKey1Queue() {
        return new Queue(DirectExchangeKey1,false);
    }
    
    @Bean
    public Queue directExchangeKey2Queue() {
        return new Queue(DirectExchangeKey2,false);
    }
    
    @Bean
    public Queue TopicNameQueue() {
        return new Queue(TopicName,false);
    }
    
    @Bean
    public Queue TopicNameQueues() {
        return new Queue(TopicNames,false);
    }
}